package org.yangspring.samples.mvc.CtrlOracle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yangspring.samples.mvc.domainOracle.Employee;
import org.yangspring.samples.mvc.domainOracle.Salgrade;
import org.yangspring.samples.mvc.serviceOracle.EmployeeService;
import org.yangspring.samples.mvc.serviceOracle.SalgradeService;

import java.util.List;

import static java.lang.System.out;

/**
 * Created by franklin on 6/21/2017.
 */

@Controller
@RequestMapping("/oracle/scott")
public class OracleInfoCtrl {

    private static final Logger logger = LoggerFactory.getLogger(OracleInfoCtrl.class);

    @Autowired
//    @Resource(name = "employeeService")
    private EmployeeService employeeService;

    @Autowired
//    @Resource(name = "salgradeService")
    private SalgradeService salgradeService;


    @RequestMapping(value = {"/emp", "/emp/list"})
    public String empList(Model model){
        logger.warn("\nOracle SCOTT.EMP Controller\n");

        model.addAttribute("emp001", new Employee());
        List<Employee> emps = this.employeeService.listEmp();
        logger.warn("\nEmp007 Quantity:\t" + emps.size() + "\n");
        model.addAttribute("listEmp007", emps);
        return "listEmp";
    }


    @RequestMapping(value = {"/sal", "/sal/list"})
    public String salList(Model model){
        logger.warn("\nOracle SCOTT.SALGRADE Controller\n");

        model.addAttribute("sal001", new Salgrade());
        List<Salgrade> sals = this.salgradeService.listSal();
        logger.warn("\nSal007 Quantity:\t" + sals.size() + "\n");
        model.addAttribute("listSal007", sals);
        return "listSal";
    }

}
